package timebetween;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : DurationDemo
 * @Author : 54061
 * @Date: 2022/2/12 14:05
 */
public class DurationDemo {
    public static void main(String[] args) {
        //获取时分秒的时间间隔对象

        LocalTime now = LocalTime.now();
        LocalTime time = LocalTime.of(12, 0, 0);

        //获取时间间隔
        Duration between = Duration.between(now, time);
        System.out.println("between = " + between);
        System.out.println("--------------------------------");
//        LocalDate now1 = LocalDate.now();
//        LocalDate birthDate = LocalDate.of(1990, 1, 1);
//        Duration between1 = Duration.between(birthDate, now1);
//        System.out.println("between1 = " + between1);

        LocalDateTime birthDate = LocalDateTime.of(1990, 1, 1, 8, 8, 8);
        LocalDateTime now1 = LocalDateTime.now();
        Duration between1 = Duration.between(birthDate, now1);
        System.out.println("between1 = " + between1);//PT281042H29M15.357S

        //long toDays()
        long days = between1.toDays();
        System.out.println("days = " + days);


    }
}
